# -*- coding: utf-8 -*-
"""
Created on Wed Jun 17 13:48:22 2020

@author: my
"""
import re

r = re.match('h\w*', 'helloworld', re.S)

r = re.match('h\w*', 'h', re.S)
print(r.group())

r = re.findall('do(es)?', 'id do, id does')
print(r)

r = re.findall('1\d{10,}', """aaaa15998697390d
sdf;sdfjj123123213213
123213213kl12j3kl21j4o23ji4j23oij5io254
534fefew
53
4534654767jfoiwefwe               
fd""")
print(r)

line = """Cats Are smarter than dogs"""
 
matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I)

if matchObj:
   print("matchObj.group() : %s", matchObj.group())
   print("matchObj.group(1) :%s ", matchObj.group(1))
   print("matchObj.group(2) :%s ", matchObj.group(2))
else:
   print("No match!!")
   
r = re.findall('do(?:|es)', 'id do, id does', re.S)
print(r)
r = re.findall('do(?=|es)', 'id do, id does', re.S)
print(r)
r = re.match(r'.*do(?:|es)', 'do does', re.S)
print(r.gro())up
print(r.span())

"""
aaa
"""
r = re.findall('[a-z]', """aaaa15998697390d
sdf;sdfjj123123213213
123213213kl12j3kl21j4o23ji4j23oij5io254
534fefew
53
4534654767jfoiwefwe               
fd""")
print(r)


'''
14:44上课
'''

"""
爬虫

pip install requests
"""

"""
    简单的网站爬虫
"""
from lxml import etree

import requests

import re


response = requests.get('http://neunews.neu.edu.cn/xwzh/list.htm')
response.encoding = 'utf-8'
html = response.text

#m = re.match(r'.*<span class="news_title">(.*?)</span>', html, re.S|re.M|re.I)
#print(m.group())

htmlnode = etree.HTML(html)

html_data = htmlnode.xpath('//span[contains(@class, "news_title")]/a/text()')

print(html_data)


html_data = htmlnode.xpath('//span[contains(@class, "news_title")]/a/@href')

print(html_data)


"""
淘宝
https://uland.taobao.com/sem/tbsearch?
refpid=mm_26632258_3504122_32538762
&clk1=8a2fe6f176258fb20716a8d182939dc4&
keyword=%E7%BA%A2%E5%AF%8C%E5%A3%AB%E8%8B%B9%E6%9E%9C&
page=0
"""

from lxml import etree
import requests

params = {
'jsv': '2.4.0',
'appKey': '12574478',
't': '1592380690017',
'sign': '368d4db4b977bab71716bb660e261167',
'api': 'mtop.alimama.union.sem.landing.pc.items',
'v': '1.0',
'AntiCreep': 'true',
'dataType': 'jsonp',
'type': 'jsonp',
'ecode': 0,
'callback': 'mtopjsonp1',
'data': {"keyword":"红富士苹果","ppath":"","loc":"","minPrice":"","maxPrice":"","ismall":"","ship":"","itemAssurance":"","exchange7":"","custAssurance":"","b":"","clk1":"df6530d16b3208828b55de25e9a6d643","pvoff":"","pageSize":"100","page":"0","elemtid":"1","refpid":"mm_26632258_3504122_32538762","pid":"430673_1006","featureNames":"spGoldMedal,dsrDescribe,dsrDescribeGap,dsrService,dsrServiceGap,dsrDeliver, dsrDeliverGap","ac":"zV0DFxG9PRUCASSAgdgexrXz","wangwangid":"t_1514168928654_0773","catId":""}
    }
url = 'https://h5api.m.taobao.com/h5/mtop.alimama.union.sem.landing.pc.items/1.0/?jsv=2.4.0&appKey=12574478&t=1592380690017&sign=368d4db4b977bab71716bb660e261167&api=mtop.alimama.union.sem.landing.pc.items&v=1.0&AntiCreep=true&dataType=jsonp&type=jsonp&ecode=0&callback=mtopjsonp1&data=%7B%22keyword%22%3A%22%E7%BA%A2%E5%AF%8C%E5%A3%AB%E8%8B%B9%E6%9E%9C%22%2C%22ppath%22%3A%22%22%2C%22loc%22%3A%22%22%2C%22minPrice%22%3A%22%22%2C%22maxPrice%22%3A%22%22%2C%22ismall%22%3A%22%22%2C%22ship%22%3A%22%22%2C%22itemAssurance%22%3A%22%22%2C%22exchange7%22%3A%22%22%2C%22custAssurance%22%3A%22%22%2C%22b%22%3A%22%22%2C%22clk1%22%3A%22df6530d16b3208828b55de25e9a6d643%22%2C%22pvoff%22%3A%22%22%2C%22pageSize%22%3A%22100%22%2C%22page%22%3A%220%22%2C%22elemtid%22%3A%221%22%2C%22refpid%22%3A%22mm_26632258_3504122_32538762%22%2C%22pid%22%3A%22430673_1006%22%2C%22featureNames%22%3A%22spGoldMedal%2CdsrDescribe%2CdsrDescribeGap%2CdsrService%2CdsrServiceGap%2CdsrDeliver%2C%20dsrDeliverGap%22%2C%22ac%22%3A%22zV0DFxG9PRUCASSAgdgexrXz%22%2C%22wangwangid%22%3A%22t_1514168928654_0773%22%2C%22catId%22%3A%22%22%7D'
cookie="XSRF-TOKEN=c4493474-0afd-479d-9a58-d435314cac90"
headers = {
    'Accept': 'text/html, application/xhtml+xml, image/jxr, */*',
               'Accept - Encoding':'gzip, deflate',
               'Accept-Language':'zh-Hans-CN, zh-Hans; q=0.5',
               'Connection':'Keep-Alive',
    'Referer': 'https://uland.taobao.com/sem/tbsearch?refpid=mm_26632258_3504122_32538762&clk1=df6530d16b3208828b55de25e9a6d643&keyword=%E7%BA%A2%E5%AF%8C%E5%A3%AB%E8%8B%B9%E6%9E%9C&page=0',
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063',
    'Cookie': cookie
    
    }


response = requests.get(url, headers=headers)
response.encoding = 'utf-8'

print(response.text)


"""
"""










